package gbench.appdemo.crawler.junit.jdbc;

import org.junit.jupiter.api.Test;

import java.util.stream.*;
import gbench.appdemo.crawler.luke.documents.DocumentsFactory;
import gbench.appdemo.crawler.srch.JdbcSrchApplication;
import gbench.appdemo.crawler.srch.JdbcSrchApplication.JdbcSrchEngine;
import static gbench.common.tree.LittleTree.IRecord.*;

public class JunitLuke {
    
    @Test
    public void foo() {
        jdbc.initialize();
        DocumentsFactory docf = new DocumentsFactory();
        final var doc = docf.newInstance(jdbc.getIndexReader());
        Stream.iterate(doc.firstTerm("text"),i->doc.nextTerm()).takeWhile(p->p.isPresent()).map(e->e.get()).forEach(e->{
            System.out.println(e);
        });
        
        doc.getTermVectors(1, "text")
        .stream().flatMap(e->e.getPositions().stream().map(p->REC(
            "field",doc.getCurrentField(),
            "termText",e.getTermText(),
            "position",p.getPosition(),
            "startOffset",p.getStartOffset().getAsInt(),
            "endOffset",p.getStartOffset().getAsInt()
        ))).sorted((a,b)->a.i4("position")-b.i4("position")).forEach(e->{
            System.out.println(e);
        });//
        
        doc.getDocValues(0, "text").get().getValues().forEach(e->{
            System.out.println(e.utf8ToString());
        });
        
        jdbc.uninitialize();
    }
    
    public String indexHome = "indexes";// 索引文件的路径
    public String corpusHome = "C:\\Users\\gbench\\Desktop\\中国笔记\\逻辑词汇";// 语料库的词汇目录
    public String snapHome = "D:\\sliced\\tmp\\crawlersnap";// 快照文件根目录
    final JdbcSrchApplication dataApp = new JdbcSrchApplication(indexHome, corpusHome,snapHome);// 数据应用App
    final JdbcSrchEngine jdbc = dataApp.new JdbcSrchEngine();// jdbc风格数据操作界面
}
